﻿using CommonTool;
using EFCore.Entity;
using Li.Contracts;
using Li.Repository.IRepository;
using Li.Service.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Li.Contracts.OutputDto;

namespace Li.Service.Service
{
    public class CodeUserService : BaseService<CodeUser>, ICodeUserService
    {
        private readonly ICodeUserRepository _codeUserRepository;
        private readonly ICodeRoleRepository _codeRoleRepository;
        public CodeUserService(ICodeUserRepository codeUserRepository
            , ICodeRoleRepository codeRoleRepository
            
            ) : base(codeUserRepository)
        {
            _codeUserRepository = codeUserRepository;
            _codeRoleRepository = codeRoleRepository;
        }


        public IQueryable<dynamic> GetRoleAll()
        {
            return _codeRoleRepository.GetAll();
        }
        public UserDto CheckLogin(LoginInputDto input)
        {
            var user = _codeUserRepository.GetAll()
                .WhereIf(string.IsNullOrWhiteSpace(input.UserName), x => x.UserCode.Equals(input.UserName))
                .FirstOrDefault();
            if (user != null && user.UserPassword.Equals(input.Password))
            {
                return user.MapTo<UserDto>();

            }
            return null;
        }
    }
}
